package org.ilead.iserve.dao.impl;

import java.util.List;


import org.hibernate.LockMode;
import org.ilead.iserve.dao.IHelpInformationMessageDAO;
import org.ilead.iserve.model.HelpInformationMessage;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class HelpInformationMessageDAO extends HibernateDaoSupport implements
		IHelpInformationMessageDAO {

	@Override
	public Long save(HelpInformationMessage helpInformationMessage) {
		try {
			return (Long) getHibernateTemplate().save(helpInformationMessage);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void delete(HelpInformationMessage helpInformationMessage) {
		try {
			getHibernateTemplate().delete(helpInformationMessage);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void update(HelpInformationMessage helpInformationMessage) {
		try {
			getHibernateTemplate().update(helpInformationMessage);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public HelpInformationMessage findById(Long id) {
		try {
			HelpInformationMessage instance = (HelpInformationMessage) getHibernateTemplate()
					.get("org.ilead.iserve.model.HelpInformationMessage", id);
			return instance;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<HelpInformationMessage> findByExample(HelpInformationMessage instance) {
		try {
			List<HelpInformationMessage> results = getHibernateTemplate()
					.findByExample(instance);
			return results;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	@Override
	public List<HelpInformationMessage> findByTopicId(Object topicId) {
		return findByProperty(TOPICID, topicId, "order by rid,pid,create_time asc" );
	}
	
	@Override
	public List<HelpInformationMessage> findByProperty(String propertyName,
			Object value) {
		return findByProperty(propertyName, value, "");
	}

	@SuppressWarnings("unchecked")
	public List<HelpInformationMessage> findByProperty(String propertyName, Object value, String orderBy) {
		try {
			String queryString = "from HelpInformationMessage as model where model."
					+ propertyName + "= ? " + orderBy;
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			throw re;
		}
	}



	@Override
	public HelpInformationMessage merge(HelpInformationMessage helpInformationMessage) {
		try {
			HelpInformationMessage result = (HelpInformationMessage) getHibernateTemplate()
					.merge(helpInformationMessage);
			return result;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	@Override
	public void attachDirty(HelpInformationMessage instance) {
		try {
			getHibernateTemplate().saveOrUpdate(instance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public void attachClean(HelpInformationMessage instance) {
	        try {
	            getHibernateTemplate().lock(instance, LockMode.NONE);
	        } catch (RuntimeException re) {
	            throw re;
	        }
	}
	public static IHelpInformationMessageDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (IHelpInformationMessageDAO) ctx.getBean("HelpInformationMessageDAO");
	}



}
